package com.itheima.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 增强模式
 *
 * @Aspect注解：切面
 */
@Aspect
@Component
public class AOPAdvice {

    //切入点表达是
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public void pc(){
    }

    //环绕注解
    @Around("pc()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            System.out.println("前置增强");
            proceedingJoinPoint.proceed();
            System.out.println("后置增强");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常增强");
        }finally {
            System.out.println("最终增强");
        }
    }
    //@Before("pc()")
    //public void before() {
    //    System.out.println("前置增强");
    //}
    //@After("pc()")
    //public void After() {
    //    System.out.println("最终增强");
    //}
    //@AfterReturning("pc()")
    //public void afterReturning(){
    //    System.out.println("后置增强");
    //}
    //
    //@AfterThrowing("pc()")
    //public void afterThrow() {
    //    System.out.println("异常增强");
    //}
}
